require'../main/GenRepository'
require'../main/Gen'
require'../main/Chromosome'
require'../main/SuperGen'
require'../main/GenTranslator'
require'../main/CrossOperator'
require'../main/TranslatorChromosome'
require'../main/FitnessFunction'
require'../main/TournamentSelector'
require'../main/Population'
require'../main/MutationOperator'
require'../main/PrintModule'
require'test/unit'

class SuperGenTest < Test::Unit::TestCase
	include PrintChromosome
end

class SuperGenTest < Test::Unit::TestCase
	def new_chromosome
		type = Gen.new(["CienciaFiccion","Ensayo","Otro"])
		languaje = Gen.new(["Frances","Otro","Ruso"])
		pages = Gen.new([290,"Otro"])
		longines = Gen.new(["Breve","Intermedio","Mas extenso"])
		silvia = Gentranslator.new([type,languaje,pages,longines])
		juan = Gentranslator.new([type,languaje,pages,longines])
		olga = Gentranslator.new([type,languaje,pages,longines])
		TranslatorChromosome.new([silvia,olga,juan],FitnessFunction.new)		
	end

	def test_evolve		
		population = Population.new
		population.selectors << TournamentSelector.new(8)
		population.operators << CrossOperator.new(4)
		population.operators << MutationOperator.new(0.02,0.001)
		population.chromosome_sample = new_chromosome
		population.create_population(152)
		population.evolve(500)
		assert_equal(152, population.size)
		assert_equal(3, population.get_fittess(3).size)
	end

	def test_cross_over
		GenRepository.instance.chromosome_sample = new_chromosome
		first_mate = GenRepository.instance.get_chromosome
		second_mate = GenRepository.instance.get_chromosome
		childs = []
#corro 1 ves la operacion 2*0.5
#arreglar un ratio deberia ser entre 0 y 1
#opciones:
#	en el torneo en ves de matar a los que no se seleccionan copiar a los que ganan.
		cross_over = CrossOperator.new(0.5)
		childs += cross_over.operate([first_mate,second_mate])
		assert_equal(2,childs.size)
	end

	def test_tournament
		GenRepository.instance.chromosome_sample = new_chromosome
		pop = []
		8.times{pop << GenRepository.instance.get_chromosome}
		selector = TournamentSelector.new(4)
		pop_selected = []
		pop_selected += selector.select(pop)		
		assert_equal(2,pop_selected.size)
	end

	def test_cross_over
		cross_operator = CrossOperator.new(0.5)
		subject1 = new_chromosome
		subject2 = new_chromosome
	end
end
